package org.javatribe.calculator.module.handler;

import org.javatribe.calculator.common.EventWrapper;
import org.javatribe.calculator.common.Handler;
import org.javatribe.calculator.module.view.IndexFrame;

/**
 * Created by Wenxin on 2017/9/16.
 */
public class TextFiledAppendHandler implements Handler {
    @Override
    public void handle(EventWrapper eventWrapper) {
        eventWrapper.proccess();
        IndexFrame indexFrame = (IndexFrame) eventWrapper.getFrame();
        Object source = eventWrapper.getEvent().getSource();
        if (!source.equals(indexFrame.getEQUAL_BUTTON()) && !source.equals(indexFrame.getOFF_BUTTON())&& !source.equals(indexFrame.getCLEAR_BUTTON())){
            if ("0".equals(indexFrame.getTEXT_FIELD().getText())){
                indexFrame.getTEXT_FIELD().setText("");
            }
            indexFrame.getTEXT_FIELD().setText(indexFrame.getTEXT_FIELD().getText().concat(eventWrapper.getSourceName()));
        }
    }
}
